/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sistcomptf;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;

/**
 *
 * @author Medina
 */
public class Actualizador implements Runnable {
    private JLabel tempActual;
    private String temp;
    private Integer itemp = new Integer (0);
    private Actualizable actualizar;
    private  DataInputStream inODBC;
    
    private StringBuffer buffer = new StringBuffer();
    private String line;
    private FileReader fReader;
    private BufferedReader bReader;
    
    Actualizador(JLabel tempActual) {
       
            this.tempActual = tempActual;

       }
    
    Actualizador(Actualizable actualizar){
        this.actualizar=actualizar;

    }
    public Integer readODBC(){
        Integer read=-1;
        try {
            fReader = new FileReader("ODBC.txt");
            bReader = new BufferedReader(fReader);

            
            bReader.mark(14072);
            // Ahora  crear un marcador de lineas del texto, para saber cual es la última linea
            int k=0;
            while ((line = bReader.readLine()) != null) {
                //System.out.println("1Leyendo.."+line+" "+k);
                k++;
                }
            bReader.reset();
            //Ahora leer la última linea (Será k-1):
            int j=0;
            while ((line = bReader.readLine()) != null) {
                    //System.out.println("2Leyendo.."+line+" "+k+" "+j);
                   if (j==(k-1)) //tucampo.settext(bReader.readLine());
                    {
                        read=Integer.parseInt(line);
                    }
                    j++;
                    
                }
            
         
        } catch (IOException ex) {
            Logger.getLogger(Actualizador.class.getName()).log(Level.SEVERE, null, ex);
        }
            
          this.closeRODBC();
          System.out.println("read.."+read);   
        return read;
    }
    
    public void closeRODBC(){
        try {
            //inODBC.close();
            fReader.close();
            bReader.close();
        } catch (IOException ex) {
            Logger.getLogger(Actualizador.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void run() {
        try {
                Thread.sleep(100);
            } catch (InterruptedException ex) {
                Logger.getLogger(Actualizador.class.getName()).log(Level.SEVERE, null, ex);
            }
        while(true){
            actualizar.actualizar(readODBC());
                    
        }
    }
    
    

}
